﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VK.Casemeet.Groups;
using VK.Comm;

namespace VK.Casemeet.Web.Admin.Groups
{
    public partial class CategoryList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            (this.Master as Site).SiteMapPathControl.MapPathList = new List<MapPath>(){
                new MapPath{ Text="桌面",Url="/Admin/Home.aspx"},
                new MapPath{ Text="分类列表",Url="#"}
            };

            if (!IsPostBack)
                bindReplist();
        }

        void bindReplist()
        {
            List<CategoryEntity> listcategory = GroupsBLL.GetCategories(0, txtName.Text.Trim());
           if (listcategory != null && listcategory.Count != 0)
           {
               rptCategory.DataSource = listcategory;
               rptCategory.DataBind();
           }
           else
           {
               rptCategory.DataSource = null;
               rptCategory.DataBind();
           }
        }


        protected void rptCategory_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                switch (e.CommandName)
                {
                    case "Delete":
                        if (GroupsBLL.DelGetCategory(int.Parse(e.CommandArgument.ToString())) > 0)
                        {
                            Message.Msg(this.Page, CS.MsgDelSuccess, MessageType.Success);
                        }
                        else
                        {
                            Message.Msg(this.Page, CS.MsgDelFailure, MessageType.Failure);
                        }
                        break;
                    case "MoveUp":
                        if (GroupsBLL.SetCategoryMoveUp(int.Parse(e.CommandArgument.ToString())) > 0)
                        {
                           int  selectID = int.Parse(e.CommandArgument.ToString());
                            Response.Redirect("CategoryList.aspx" );
                        }
                        else
                        {
                            Message.Msg(this.Page, "操作失败!", MessageType.Failure);
                        }
                        break;
                    case "MoveDown":
                        if (GroupsBLL.SetCategoryMoveDown(int.Parse(e.CommandArgument.ToString())) > 0)
                        {
                           int  selectID = int.Parse(e.CommandArgument.ToString());
                            Response.Redirect("CategoryList.aspx");
                        }
                        else
                        {
                            Message.Msg(this.Page, "操作失败!", MessageType.Failure);
                        }
                        break;
                }
                bindReplist();
            }
        }

        protected void butSearch_Click(object sender, EventArgs e)
        {
            bindReplist();
        }
    }
}